package edu.sandau.basic.controller;

import edu.sandau.basic.domain.Role;
import edu.sandau.basic.service.RoleService;
import edu.sandau.basic.vo.BasicMsg;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;

import java.util.List;

@RestController
@RequestMapping("/api/roles")
@Tag(name = "角色管理", description = "角色的增删改查接口")
public class RoleController {

    @Resource
    private RoleService roleService;

    @GetMapping
    @Operation(summary = "获取全部角色")
    public List<Role> listRoles() {
        return roleService.listAll();
    }

    @GetMapping("/{id}")
    @Operation(summary = "根据ID查询角色")
    public Role getRole(@PathVariable Integer id) {
        return roleService.getById(id);
    }

    @PostMapping
    @Operation(summary = "新增角色")
    public BasicMsg createRole(@RequestBody Role role) {
        return roleService.addRole(role);
    }

    @PutMapping("/{id}")
    @Operation(summary = "修改角色信息")
    public BasicMsg updateRole(@PathVariable Integer id, @RequestBody Role role) {
        return roleService.updateRole(id, role);
    }

    @PatchMapping("/{id}")
    @Operation(summary = "部分更新角色信息")
    public BasicMsg patchRole(@PathVariable Integer id, @RequestBody Role role) {
        return roleService.patchRole(id, role);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除角色")
    public BasicMsg deleteRole(@PathVariable Integer id) {
        return roleService.deleteRole(id);
    }

    @GetMapping("/active")
    @Operation(summary = "获取启用状态的角色")
    public List<Role> listActiveRoles() {
        return roleService.listActive();
    }
}
